package org.zakariya.flyoutmenudemo.menus;


import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;
import org.zakariya.flyoutmenu.FlyoutMenuView;

import java.math.BigInteger;

public class EmojiFlyoutMenu {

    /**
     * unicode 转 emoji
     *
     * @param unicode16 the unicode
     * @return emoji
     */
    public static String uni2emoji(String unicode16) {
        if (unicode16.length() <= 0) {
            return null;
        }
        BigInteger bi = new BigInteger(unicode16, 16);
        String biemoji = bi.toString(10);
        Integer integer = Integer.valueOf(biemoji);
        String emoji = new String(Character.toChars(integer));
        return emoji;
    }


    public static class MenuItem extends FlyoutMenuView.MenuItem {

        String emojiString;
        Paint paint;

        public MenuItem(Context context, int id, String emojiCode, float size, int color) {
            super(context, id);  //type = 1
            this.emojiString = emojiCode;


            paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(new Color(0xFFA30303));
            paint.setTextSize(96);//(int) size);106
            paint.setStyle(Paint.Style.FILL_STYLE);
            paint.setTextAlign(TextAlignment.CENTER);

        }

        public String getEmojiCode() {
            return emojiString;
        }


        @Override
        public void onDraw(Canvas canvas, RectFloat bounds, float degreeSelected) {
            canvas.drawText(paint, uni2emoji(emojiString), bounds.getCenter().getPointX(), (bounds.bottom + bounds.top) / 2 + paint.descent() + 5);//uni2emoji(emojiString)
        }
    }

    public static class ButtonRenderer extends FlyoutMenuView.ButtonRenderer {  //可以设置外圈的颜色

        String emojiString;
        Paint paint;
        Paint paint1;

        public ButtonRenderer(String emojiCode, float size, int color) {
            super();

            this.setEmojiCode(emojiCode);
            paint1 = new Paint();
            paint1.setColor(new Color(0xFFA30303));


            paint = new Paint();
            paint.setAntiAlias(true);
//            paint.setColor(new Color(0xFFA30303));
            paint.setColor(new Color(0xFFA30303));
            paint.setTextSize(96);
            paint.setTextAlign(TextAlignment.CENTER);
            paint.setStyle(Paint.Style.FILL_STYLE);
        }

        public String getEmojiCode() {
            return emojiString;
        }

        public void setEmojiCode(String emojiCode) {
//            this.emojiCode = emojiCode;
            this.emojiString = emojiCode;
        }

        @Override
        public void onDrawButtonContent(Canvas canvas, RectFloat buttonBounds, Color buttonColor, float alpha) {//实现button按钮上内容的绘制
            canvas.drawText(paint, uni2emoji(emojiString), buttonBounds.getCenter().getPointX(), buttonBounds.getCenter().getPointY() + paint.descent() + 10);  //可以实现
        }
    }
}
